/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.uhk.ppro.response.web;


import cz.uhk.ppro.response.model.MobileTests;
import cz.uhk.ppro.response.model.Test;
import cz.uhk.ppro.response.service.DatabaseService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

 
@Controller
public class MobileTestsController {
 
        @Autowired
        private DatabaseService databaseSession;
    
	@RequestMapping(value="testsmobileresponse", method = RequestMethod.POST)
	public @ResponseBody MobileTests getTestsInJSON(
                                     //   @PathVariable String userId
                                        @RequestParam(value="idStudent",required=false) String userId
                ) {
 
            
              MobileTests mobtesty = new MobileTests();
              List <Test> tests = databaseSession.getTestsByUserId(Integer.parseInt(userId));
              for(Test t: tests) {
                mobtesty.addTestId(t.getId(), t.getName());
                 // mobtesty.addString(t.getName());
              }
              
               return mobtesty;
	}
 
}